<!DOCTYPE html>
<html>
<head>
    {include file="layout:_meta" /}
    <link rel="stylesheet" href="__static__/admin/style/dtree/dtree.css" media="all">
    <link rel="stylesheet" href="__static__/admin/style/dtree/font/dtreefont.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">父级菜单</label>
        <div class="layui-input-block">
            <ul id="selTree" class="dtree" data-id="0" ></ul>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限类型</label>
        <div class="layui-input-block">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单图标</label>
        <div class="layui-input-block">
            <input name="menu_icon" type="text" id="iconPicker" lay-filter="iconPicker" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">规则标识</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" placeholder="请输入规则标识 如:admin/auth/index"  value="{:isset($list.name)?$list.name:''}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" placeholder="请输入权限名称 如:权限管理"  value="{:isset($list.title)?$list.title:''}" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="hidden" name="id" value="{:isset($list['id'])?$list['id']:''}">
        <input type="button" lay-submit lay-filter="addEdit" id="addEdit" value="确认">
    </div>
</div>
{include file="layout:_footer" /}
<script>
    var menu_icon="{:isset($list['menu_icon'])?$list['menu_icon']:''}";
    var pid="{:isset($list['pid'])?$list['pid']:$pid}";    //select选择框初始化值
    layui.config({
        base: '__static__/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','dtree','form','iconPicker'], function(){
        var form = layui.form,$ = layui.$,iconPicker = layui.iconPicker,dtree = layui.dtree;

        dtree.renderSelect({
            elem: "#selTree",
            url: "{:url('auth/edit')}",
            selectCardHeight: "150",
            selectInitVal:pid,
            initLevel:3,
            method: "get",  //默认为post
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            dataFormat: "list",  //配置data的风格为list
            response:{message:"msg",statusCode:0},  //修改response中返回数据的定义
            skin: "layui",  // laySimple主题风格
            selectInputName: {
                nodeId: "pid"   //隐藏的表单输入框指定名称
            }

        });

        iconPicker.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // 数据类型：fontClass/unicode，推荐使用fontClass
            type: 'fontClass',
            // 是否开启搜索：true/false
            search: true,
            // 点击回调
            click: function (data) {
                console.log(data);
            }
        });

        //如果不是添加的数据赋值图标选择器
        if (menu_icon!=""){
            iconPicker.checkIcon('iconPicker', menu_icon);
        }

        form.on('switch(state)', function(data){
            this.value = this.checked?1:0;
        });
    })
</script>
</body>
</html>